#ifndef _SMOOTH_
#define _SMOOTH_

/////////// TEMPLATE CLASS FOR SMOOTHING THE DATA
#include <vector>
#include <algorithm> 
template <class T>
class CSmooth
{
 public:
  CSmooth(std::vector<T> *vec, int Wnd=2): m_vec(vec), sm(Wnd){Np=(*vec).size();};
  ~CSmooth(){};
  std::vector<T>  GetSmoothed(int n_smooth=1)
    {
      std::vector<T> vsm( Np);
      
      /////////////////////////
      T rhomean;
      T count;
      int sm2=static_cast<int>(0.5*sm);
      int ks, ke, kk, k;
      vsm=(*m_vec);
      ke=Np-sm2-1;
      ks=sm2;
      for(int nit=0;nit<n_smooth;nit++)
	{      
	  for(kk=ks;kk<ke;kk++)
	    {
	      rhomean=(T)0.0;
	      count=(T)0.0;
	      for(k=kk-sm2;k<=kk+sm2;k++)
		{
		  rhomean+= (*m_vec)[k];
		  count+=(T)1.0;
	    }
	      vsm[kk]=(rhomean/count);
	    }
	  //	  std::cout<<"# Smoothed: "<<nit+1<<" times."<<std::endl;
	}
      ///////////////////////// 
      return vsm;
      
    };
inline void  SetVector(std::vector<T> *vec){m_vec=vec;}    
 
 private:
  std::vector<T> *m_vec;
  int Np;
  int sm;
  int Nsmooth;
};

#endif
